﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.Model;
using Automobile.service.BLL;
using System.Data;

namespace Automobile.service.UI
{
    public partial class UpdateDocument : System.Web.UI.Page
    {
        DocumentBll bll=new DocumentBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["fid"] != null)
                {
                    LoadData();
                }
            }
        }

        private void LoadData()
        {
            this.TextBox1.Text = Request.QueryString["fid"].ToString();

            DataTable dt = bll.GetDocument(this.TextBox1.Text);
            if (dt != null)
            {
                this.TextBox3.Text = dt.Rows[0][1].ToString();
                this.TextBox4.Text = dt.Rows[0][2].ToString();
                this.TextBox5.Text = dt.Rows[0][3].ToString();
                this.TextBox6.Text = dt.Rows[0][4].ToString();
                this.TextBox7.Text = dt.Rows[0][5].ToString();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            DocumentModel d = new DocumentModel();
            d.Document_Id =Convert.ToInt32(this.TextBox1.Text);
            d.Document_Type_Name = this.TextBox3.Text;
            d.WareHose_Id = Convert.ToInt32(this.TextBox4.Text);
            d.Document_Date = Convert.ToDateTime(this.TextBox5.Text);
            d.Employee_Id = Convert.ToInt32(this.TextBox6.Text);
            d.Document_Remark = this.TextBox7.Text;
            if (bll.UpdateDocument(d) > 0)
            {
                Response.Write("<script>alert('修改成功!');location.href='Document.aspx';</script>");               
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("Document.aspx");
        }
    }
}